package cn.iocoder.yudao.framework.message;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 客户端请求消息公共类
 *
 * @author: wds_prc
 * @since: 2024/7/9 22:25
 */
public class ClientRequest extends BaseWebSocketMessage {

    public <T> T readBody(Class<T> clazz) {
        T t = null;
        if (this.getData() != null) {
            t = ((JSONObject) getData()).toJavaObject(clazz);
        }
        return t;
    }

    public <T> List<T> readArrayBody(Class<T> clazz) {
        List<T> list = new ArrayList<>(1);
        if (this.getData() != null) {
            list = ((JSONArray) getData()).toJavaList(clazz);
        }
        return list;
    }


}
